﻿using System.IO;

namespace Silent.Data.Serialization
{
    public static class SerializationUtility
    {
        private static readonly ISerializationServiceGeneric xmlSerialization = new XmlSerializationService();
        private static readonly ISerializationService jsonSerialization = new JsonSerializationService();
        private static readonly ISerializationService binarySerialization = new BinarySerializationService();

        public static void Serialize<T>(T source, string filename, SerializationType type = SerializationType.Xml)
        {
            switch (type)
            {
                case SerializationType.Xml:
                    xmlSerialization.Serialize(source, filename);
                    break;
                case SerializationType.Json:
                case SerializationType.Binary:
                    return;
            }
        }
        public static void Serialize<T>(T source, Stream stream, SerializationType type = SerializationType.Xml)
        {
            switch (type)
            {
                case SerializationType.Xml:
                    xmlSerialization.Serialize(source, stream);
                    break;
                case SerializationType.Json:
                case SerializationType.Binary:
                    return;
            }
        }
        public static T Deserialize<T>(string filename, SerializationType type = SerializationType.Xml)
        {
            switch (type)
            {
                case SerializationType.Xml:
                    xmlSerialization.Deserialize<T>(filename);
                    break;
                case SerializationType.Json:
                case SerializationType.Binary:
                    return default(T);
            }
            return default(T);
        }
        public static T Deserialize<T>(Stream source, SerializationType type = SerializationType.Xml)
        {
            switch (type)
            {
                case SerializationType.Xml:
                    xmlSerialization.Deserialize<T>(source);
                    break;
                case SerializationType.Json:
                case SerializationType.Binary:
                    return default(T);
            }
            return default(T);
        }
    }
}